﻿using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
using System;
using System.Collections.Generic;
using System.Text;

namespace Template.CodeGenerator
{
   public abstract class DbServicesFactory
    {
        private readonly DbOptions _dbOptions = null;
        private readonly IServiceCollection _services;
        public DbServicesFactory(IOptions<DbOptions> dbOptions, IServiceCollection services)
        {
            _dbOptions = dbOptions.Value;
            _services = services;
        }


        private static Dictionary<DatabaseType, Type> _dic = new Dictionary<DatabaseType, Type>()
        {
            [DatabaseType.SqlServer] = typeof(SqlServiceDbServices),
            [DatabaseType.MySql] = typeof(MySqlDbServices),

        };

        public ServiceProvider CreateDbService()
        {

            _services.AddScoped(typeof(IDbServices), _dic[_dbOptions.DatabaseType]);
            return _services.BuildServiceProvider();
        }

        
    }
}
